<template>
  <li
    @click="onClickItem"
    :class="[
      'dropdown-item',
      { 'is-disabled': disabled },
      { 'is-active': path === pathName },
    ]"
  >
    <slot></slot>
  </li>
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
import { pathName, emitter } from "@/components/Dropdown.vue";
export default defineComponent({
  name: "dropdownItem",
  props: {
    disabled: {
      default: false,
      type: Boolean,
    },
    path: {
      type: String,
      required: true,
    },
  },
  setup(props, ctx) {
    function onClickItem() {
      emitter.emit("itemClick", props.path);
    }
    return {
      pathName,
      onClickItem,
    };
  },
});
</script>

<style lang="scss">
// scoped 用于在本页面上的样式
.dropdown-item a {
  display: block;
  padding: 6px 0;
  font-weight: 400;
  color: #212529;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  background-color: transparent;
  cursor: pointer;
}
.dropdown-item.is-active * {
  color: #3182bd !important;
}
.dropdown-item.is-disabled * {
  color: #6c757d !important;
  cursor: not-allowed;
  background-color: transparent;
}
</style>
